package com.example.aotdemo;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {
    @Around("execution(* com.example.aotdemo.UserService3.read(..))")
    public void log(ProceedingJoinPoint proceedingJoinPoint) {
        long startTime = System.currentTimeMillis();
        System.out.println("方法开始执行:");
        try {
            //执行具体方法
            Object proceed = proceedingJoinPoint.proceed();
        } catch (Throwable e) {
            System.out.println("执行方法异常：" + e.getMessage());
        }
        long endTime = System.currentTimeMillis();
        System.out.println("方法结束结束:");
        System.out.println("方法用时：" + (startTime - endTime) + " ms");
    }
}
